package com.fafu.control;

import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.handler.annotation.MessageMapping;
import org.springframework.messaging.handler.annotation.SendTo;
import org.springframework.messaging.simp.SimpMessagingTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import util.JsonRsp;

@Api("websocket 广播接口")
@RestController
@RequestMapping("/test")
public class WsController {
    @Autowired
    private SimpMessagingTemplate messagingTemplate;

//    @RequestMapping("/ttt")
//    public JsonRsp ttt(){
//        System.out.println(123);
//        //直接发送
//        messagingTemplate.convertAndSend("/demo_2/topic/getResponse","123");
//        return JsonRsp.success("123");
//    }

    @MessageMapping("welcome")//前端传数据
    @SendTo("/demo_2/topic/getResponse")//广播到前端
    public String say(String message) throws Exception {
        System.out.println("into method");
        return "1231231231";
    }
}